/*
 * Copyright (c) 2011 Ball State University
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package edu.bsu.android.gtv.apps.bconnected.objects;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * Event object
 * @author Kyle Parker, University Computing Services
 */
public class Event implements Comparable<Event> {
	private String audience;
	private String beginDate;
	private String beginTime;
	private String buildingCode;
	private String buildingDesc;
	private String calendarEventID;
	private String calendarEventName;
	private String contactPhone;
	private String contactName;
	private String contactEmail;
	private String cost;
	private String endDate;
	private String endTime;
	private String error;
	private String eventDesc;
	private String eventName;
	private URL imageURL;
	private String latitude;
	private String location;
	private String longitude;
	private URL shareURL;
	private String termID;
	private String universityCalendarID;

	public String getAudience() {
		return audience;
	}
	public void setAudience(String value) {
		this.audience = value.trim();
	}

	public String getBeginDate() {
		return beginDate;
	}
	public void setBeginDate(String value)  {
		this.beginDate = value.trim();
	}

	public String getBeginTime() {
		return beginTime;
	}
	public void setBeginTime(String value) {
		this.beginTime = value.trim();
	}

	public String getBuildingCode() {
		return buildingCode;
	}
	public void setBuildingCode(String value) {
		this.buildingCode = value.trim();
	}

	public String getBuildingDesc() {
		return buildingDesc;
	}
	public void setBuildingDesc(String value) {
		this.buildingDesc = value.trim();
	}
	
	public String getCalendarEventID()  {
		return calendarEventID;
	}
	public void setCalendarEventID(String value)  {
		this.calendarEventID = value.trim();
	}

	public String getCalendarEventName() {
		return calendarEventName;
	}
	public void setCalendarEventName(String value) {
		this.calendarEventName = value.trim();
	}

	public String getContactEmail() {
		return contactEmail;
	}
	public void setContactEmail(String value) {
		this.contactEmail = value.trim();
	}

	public String getContactName() {
		return contactName;
	}
	public void setContactName(String value) {
		this.contactName = value.trim();
	}

	public String getContactPhone() {
		return contactPhone;
	}
	public void setContactPhone(String value) {
		this.contactPhone = value.trim();
	}

	public String getCost() {
		return cost;
	}
	public void setCost(String value) {
		this.cost = value.trim();
	}
	
	public String getEndDate()  {
		return endDate;
	}
	public void setEndDate(String value) {
		this.endDate = value.trim();
	}

	public String getEndTime() {
		return endTime;
	}
	public void setEndTime(String value) {
		this.endTime = value.trim();
	}

	public String getError() {
		return error;
	}
	public void setError(String value)  {
		this.error = value.trim();
	}	

	public String getEventDesc() {
		return eventDesc;
	}
	public void setEventDesc(String value)  {
		this.eventDesc = value.trim();
	}	
	
	public String getEventName()  {
		return eventName;
	}	
	public void setEventName(String value)  {
		this.eventName = value.trim();
	}
	
	public URL getImageURL() {
		return imageURL;
	}	
	public void setImageURL(String value) {
		try {
			this.imageURL = new URL(value);
		} catch (MalformedURLException e) {
			this.imageURL = null;
		}
	}

	public String getLatitude() {
		return latitude;
	}
	public void setLatitude(String value) {
		this.latitude = value.trim();
	}

	public String getLocation() {
		return location;
	}
	public void setLocation(String value) {
		this.location = value.trim();
	}

	public String getLongitude() {
		return longitude;
	}
	public void setLongitude(String value) {
		this.longitude = value.trim();
	}
	
	public URL getShareURL() {
		return shareURL;
	}	
	public void setShareURL(String value) {
		try  {
			this.shareURL = new URL(value);
		} catch (MalformedURLException e) {
			this.shareURL = null;
		}
	}
	
	public String getTermID() {
		return termID;
	}
	public void setTermID(String value) {
		this.termID = value.trim();
	}

	public String getUniversityCalendarID() {
		return universityCalendarID;
	}
	public void setUniversityCalendarID(String value)  {
		this.universityCalendarID = value.trim();
	}
	
	public Event copy() {
		Event copy = new Event();
		copy.audience = audience;
		copy.beginDate = beginDate;
		copy.beginTime = beginTime;
		copy.buildingCode = buildingCode;
		copy.buildingDesc = buildingDesc;
		copy.calendarEventID = calendarEventID;
		copy.calendarEventName = calendarEventName;
		copy.contactEmail = contactEmail;
		copy.contactName = contactName;
		copy.contactPhone = contactPhone;
		copy.cost = cost;
		copy.endDate = endDate;
		copy.endTime = endTime;
		copy.error = error;
		copy.eventName = eventName;
		copy.eventDesc = eventDesc;
		copy.imageURL = imageURL;
		copy.latitude = latitude;
		copy.location = location;
		copy.longitude = longitude;
		copy.shareURL = shareURL;
		copy.termID = termID;
		copy.universityCalendarID = universityCalendarID;
		return copy;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;

		result = prime * result + ((audience == null) ? 0 : audience.hashCode());
		result = prime * result + ((beginDate == null) ? 0 : beginDate.hashCode());
		result = prime * result + ((buildingCode == null) ? 0 : buildingCode.hashCode());
		result = prime * result + ((buildingDesc == null) ? 0 : buildingDesc.hashCode());
		result = prime * result + ((calendarEventID == null) ? 0 : calendarEventID.hashCode());
		result = prime * result + ((calendarEventName == null) ? 0 : calendarEventName.hashCode());
		result = prime * result + ((contactEmail == null) ? 0 : contactEmail.hashCode());
		result = prime * result + ((contactName == null) ? 0 : contactName.hashCode());
		result = prime * result + ((contactPhone == null) ? 0 : contactPhone.hashCode());
		result = prime * result + ((cost == null) ? 0 : cost.hashCode());
		result = prime * result + ((endDate == null) ? 0 : endDate.hashCode());
		result = prime * result + ((beginTime == null) ? 0 : beginTime.hashCode());
		result = prime * result + ((endTime == null) ? 0 : endTime.hashCode());
		result = prime * result + ((error == null) ? 0 : error.hashCode());
		result = prime * result + ((eventDesc == null) ? 0 : eventDesc.hashCode());
		result = prime * result + ((eventName == null) ? 0 : eventName.hashCode());
		result = prime * result + ((imageURL == null) ? 0 : imageURL.hashCode());
		result = prime * result + ((latitude == null) ? 0 : latitude.hashCode());
		result = prime * result + ((location == null) ? 0 : location.hashCode());
		result = prime * result + ((longitude == null) ? 0 : longitude.hashCode());
		result = prime * result + ((shareURL == null) ? 0 : shareURL.hashCode());
		result = prime * result + ((termID == null) ? 0 : termID.hashCode());
		result = prime * result + ((universityCalendarID == null) ? 0 : universityCalendarID.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj) { return true; }
		
		if (obj == null) { return false; }
		
		if (getClass() != obj.getClass()) { return false; }
		
		Event other = (Event) obj;
		
		if (audience == null) {
			if (other.audience != null) { return false; }
		} else if (!audience.equals(other.audience)) { return false; }
		
		if (beginDate == null) {
			if (other.beginDate != null) { return false; }
		} else if (!beginDate.equals(other.beginDate)) { return false; }
		
		if (beginTime == null) {
			if (other.beginTime != null) { return false; }
		} else if (!beginTime.equals(other.beginTime)) { return false; }
		
		if (buildingCode == null) {
			if (other.buildingCode != null) { return false; }
		} else if (!buildingCode.equals(other.buildingCode)) { return false; }
		
		if (buildingDesc == null) {
			if (other.buildingDesc != null) { return false; }
		} else if (!buildingDesc.equals(other.buildingDesc)) { return false; }

		if (calendarEventID == null) {
			if (other.calendarEventID != null) { return false; }
		} else if (!calendarEventID.equals(other.calendarEventID)) { return false; }
		
		if (calendarEventName == null) {
			if (other.calendarEventName != null) { return false; }
		} else if (!calendarEventName.equals(other.calendarEventName)) { return false; }
		
		if (contactEmail == null) {
			if (other.contactEmail != null) { return false; }
		} else if (!contactEmail.equals(other.contactEmail)) { return false; }
		
		if (contactName == null) {
			if (other.contactName != null) { return false; }
		} else if (!contactName.equals(other.contactName)) { return false; }
		
		if (contactPhone == null) {
			if (other.contactPhone != null) { return false; }
		} else if (!contactPhone.equals(other.contactPhone)) { return false; }
		
		if (cost == null) {
			if (other.cost != null) { return false; }
		} else if (!cost.equals(other.cost)) { return false; }
		
		if (endDate == null) {
			if (other.endDate != null) { return false; }
		} else if (!endDate.equals(other.endDate)) { return false; }
		
		if (error == null) {
			if (other.error != null) { return false; }
		} else if (!error.equals(other.error)) { return false; }
		
		if (eventDesc == null) {
			if (other.eventDesc != null) { return false; }
		} else if (!eventDesc.equals(other.eventDesc)) { return false; }
		
		if (eventName == null) {
			if (other.eventName != null) { return false; }
		} else if (!eventName.equals(other.eventName)) { return false; }
		
		if (endTime == null) {
			if (other.endTime != null) { return false; }
		} else if (!endTime.equals(other.endTime)) { return false; }
		
		if (imageURL == null) {
			if (other.imageURL != null) { return false; }
		}  else if (!imageURL.equals(other.imageURL)) { return false; }
		
		if (latitude == null) {
			if (other.latitude != null) { return false; }
		} else if (!latitude.equals(other.latitude)) { return false; }
		
		if (location == null) {
			if (other.location != null) { return false; }
		} else if (!location.equals(other.location)) { return false; }
		
		if (longitude == null) {
			if (other.longitude != null) { return false; }
		} else if (!longitude.equals(other.longitude)) { return false; }
		
		if (shareURL == null) {
			if (other.shareURL != null) { return false; }
		} else if (!shareURL.equals(other.shareURL)) { return false; }
		
		if (termID == null) {
			if (other.termID != null) { return false; }
		} else if (!termID.equals(other.termID)) { return false; }
		
		if (universityCalendarID == null) {
			if (other.universityCalendarID != null) { return false; }
		} else if (!universityCalendarID.equals(other.universityCalendarID)) { return false; }
		
		return true;
	}

	public int compareTo(Event another) {
		if (another == null) return 1;
		return another.universityCalendarID.compareTo(universityCalendarID);
	}
}
